home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / misc / emu / flamingo.lha / Flamingo / sources / CGX.asm < prev    next >
Encoding:
Assembly Source File  |  1999-07-13  |  7.6 KB  |  446 lines

  1. ; CGX-Direct driver (need 352x262 8 bit screen)
  2. ; External Video Driver for
  3. ; Flaming Plus/4 emulator for the Amiga
  4. ;
  5. ; version 1.1
  6. ; 1.2: added MODULO support (08.07.99)
  7. ; 1.3: added config support (12.07.99)
  8.  
  9. TRUE    equ    1
  10. FALSE    equ    0
  11.         INCDIR    Include3.1:
  12.  
  13.     INCLUDE exec/types.i
  14.     INCLUDE    exec/memory.i
  15.     INCLUDE    exec_lib.i
  16.     INCLUDE    utility/tagitem.i
  17.     INCLUDE    intuition/intuition.i
  18.     INCLUDE    intuition_lib.i
  19.     INCLUDE    intuition/screens.i
  20.     INCLUDE graphics/modeid.i
  21.     INCLUDE    graphics/rastport.i
  22. ;    INCLUDE    macros.i
  23.     INCLUDE    libraries/cybergraphics_lib.i
  24.     INCLUDE    cybergraphics/cybergraphics.i
  25.     INCLUDE    dos_lib.i
  26.     INCLUDE    dos/dostags.i
  27.     INCLUDE    dos/dosextens.i
  28.     INCLUDE    dos/var.i
  29.  
  30.  
  31.  
  32. ;*** Handler structure
  33.  
  34.  STRUCTURE vxd_handler,0
  35.  
  36.   LONG intuibase
  37.   LONG dosbase
  38.   LONG myscr
  39.   LONG mywin
  40.   LONG planes
  41.   WORD xsize
  42.   WORD ysize
  43.   LONG palette
  44.   LONG palette32
  45.   LONG emuscr
  46.   WORD bytesperrow
  47.   LONG cybbase
  48.   LONG screendim
  49.  LABEL    vxd_handler_SIZEOF
  50.  
  51.  
  52. JSRLIB    MACRO
  53.     jsr    _LVO\1(a6)
  54.     ENDM
  55.  
  56. ;*** Let's begin
  57.  
  58.     moveq.l    #0,d0
  59.     rts
  60.  
  61.     dc.b "FLAMINGOXVD"
  62.     dc.b "1"
  63.  
  64.     dc.l Name
  65.     dc.l Author
  66.     dc.w 1
  67.     dc.w 3
  68.  
  69.     dc.l drv_Init
  70.     dc.l drv_Done
  71.     dc.l drv_Configure
  72.     dc.l drv_OpenScreen
  73.     dc.l drv_CloseScreen
  74.     dc.l drv_Refresh
  75.  
  76. Name:    dc.b    "CGX-Direct External Video Driver 1.3 (12.07.99)",0
  77. Author:    dc.b    "László (pH03N1x) Török",0
  78.  
  79.     EVEN
  80.  
  81. ;*** Functions
  82.  
  83. drv_Init:
  84.     movem.l    a0-a1,-(sp)    ;Saving infos
  85.     move.l  4.w,a6        ;Alloc memory for handler
  86.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  87.     move.l    #vxd_handler_SIZEOF,d0
  88.     JSRLIB    AllocVec
  89.     movem.l    (sp)+,a0-a1    ;Recover infos
  90.         tst.l    d0
  91.     beq.b    b1        ;No mem
  92.     movea.l    d0,a2
  93.  
  94.         move.l    4(a0),dosbase(a2)    ;Saving dos.library base
  95.         move.l    8(a0),intuibase(a2)    ;Saving intuition.library base
  96.  
  97.         movem.l    d0,-(sp)
  98.     move.l    dosbase(a2),a6        ;Reading config file
  99.     move.l    #configfile,d1        ;Config file is pretty simple:
  100.     move.l    #MODE_OLDFILE,d2    ;only a screenmode number
  101.     JSRLIB    Open
  102.     tst.l    d0
  103.     beq.b    .2            ;Failed open
  104.     move.l    d0,d1
  105.     move.l    (sp),a0
  106.     lea    screendim(a0),a0
  107.     move.l    a0,d2
  108.     moveq.l    #4,d3
  109.     movem.l    d0,-(sp)
  110.     JSRLIB    Read            ;Reading the 4 bytes
  111.     cmp.l    #4,d0
  112.     beq.b    .3
  113.     move.l    (sp),a0            ;Failed: set 0 instead garbage
  114.     move.l    #0,screendim(a0)
  115.  
  116. .3    movem.l    (sp)+,d1
  117.     JSRLIB    Close
  118.  
  119. .2    movem.l    (sp)+,d0
  120.  
  121. b1    move.l    #err_nomem,d1        ;Ignored, if D0 not 0
  122.     rts                ;Result in D0 available for now
  123.  
  124. drv_Done:
  125.     movea.l    a0,a1
  126.     tst.l    a1
  127.     beq.b    c1
  128.     move.l    4.w,a6
  129.     JSRLIB    FreeVec        ;Deallocate handler
  130. c1
  131.     rts
  132.  
  133.  
  134. drv_Configure:            ;Configure
  135.                 ;A simple screenmode requester appears
  136.     movem.l    a0,-(sp)
  137.  
  138.     move.l    a0,a5
  139.     move.l    screendim(a5),ScrDisplayID
  140.  
  141.     moveq    #$00,d0
  142.     moveq    #$00,d1
  143.     move.w    xsize(a5),d0
  144.     move.w    ysize(a5),d1
  145.  
  146.     move.l    d0,cgfxmodewidth
  147.     move.l    d1,cgfxmodeheight
  148.  
  149.     move.l    4.w,a6
  150.     lea    cyblib(pc),a1
  151.     moveq    #40,d0
  152.     jsr    _LVOOpenLibrary(a6)
  153.     move.l    d0,cybbase(a5)
  154.     beq.b    configbug
  155.  
  156.     move.l    cybbase(a5),a6
  157.     lea    cybreqtags(pc),a1
  158.     jsr    _LVOCModeRequestTagList(a6)
  159.  
  160.     cmp.l    #INVALID_ID,d0
  161.     bne.b    config2
  162.  
  163.     move.l    (4).w,a6
  164.     move.l    cybbase(a5),a1
  165.     jsr    _LVOCloseLibrary(a6)
  166.     clr.l    cybbase(a5)
  167.  
  168. configbug:
  169.     suba.l    a0,a0
  170.     move.l    intuibase(a5),a6
  171.     jsr    _LVODisplayBeep(a6)
  172.     lea    4(sp),sp
  173.     rts
  174.  
  175. config2:
  176.     move.l    d0,screendim(a5)
  177.     
  178.     move.l    dosbase(a5),a6        ;Writing config file
  179.     move.l    #configfile,d1        ;Config file is pretty simple:
  180.     move.l    #MODE_NEWFILE,d2    ;only a screenmode number
  181.     JSRLIB    Open
  182.     tst.l    d0
  183.     beq.b    .1            ;Failed open
  184.     move.l    d0,d1
  185.     move.l    (sp),a0
  186.     lea    screendim(a0),a0
  187.     move.l    a0,d2
  188.     moveq.l    #4,d3
  189.     movem.l    d0,-(sp)
  190.     JSRLIB    Write            ;Writing the 4 bytes
  191.  
  192.     movem.l    (sp)+,d1        ;We don't care too much on
  193.     JSRLIB    Close            ;success...
  194.  
  195. .1
  196.     move.l    (4).w,a6
  197.     move.l    cybbase(a5),a1
  198.     jsr    _LVOCloseLibrary(a6)
  199.     clr.l    cybbase(a5)
  200.  
  201.     movem.l    (sp)+,a0
  202.     rts
  203.  
  204.  
  205.  
  206. drv_OpenScreen:
  207.     movea.l a0,a5
  208.  
  209.     move.l    screendim(a0),ScrDisplayID
  210.  
  211.     move.w    (a1)+,xsize(a5)
  212.     move.w    (a1)+,ysize(a5)
  213.     move.l    (a1)+,palette(a5)
  214.  
  215.     move.l    4.w,a6
  216.     lea    cyblib(pc),a1
  217.     moveq    #40,d0
  218.     jsr    _LVOOpenLibrary(a6)
  219.     move.l    d0,cybbase(a5)
  220.     beq.w    e0
  221.  
  222.     move.w    xsize(a5),cybwidth+2
  223.     move.w    ysize(a5),cybheight+2
  224.  
  225.     tst.l    ScrDisplayID(pc)
  226.     bne.b    modeisready
  227.  
  228.     moveq    #$00,d0
  229.     moveq    #$00,d1
  230.     move.w    xsize(a5),d0
  231.     move.w    ysize(a5),d1
  232.  
  233.     lea    cybmodetags(pc),a0
  234.     move.l    cybbase(a5),a6
  235.     jsr    _LVOBestCModeIDTagList(a6)
  236.     move.l    d0,ScrDisplayID
  237.  
  238. modeisready:
  239.     move.l    4.w,a6
  240.     move.l    #MEMF_PUBLIC,d1
  241.     move.l    #128*3*4+8,d0
  242.     JSRLIB    AllocVec
  243.     move.l    d0,palette32(a5)    ;Convert palette to 32 bit per gun
  244.     beq.w    e1
  245.     movea.l    d0,a0
  246.         move.l    palette(a5),a1
  247.     move.w    #128,(a0)+
  248.     move.w    #$0,(a0)+
  249.     move.l    #128*3-1,d2
  250. e2    moveq.l    #0,d0
  251.     move.b    (a1)+,d0
  252.     swap    d0
  253.     asl.l    #8,d0
  254.     move.l    d0,(a0)+
  255.     dbf    d2,e2
  256.     move.l    #0,(a0)
  257.     move.w    xsize(a5),width+2
  258.     move.w    ysize(a5),height+2
  259.     move.l    palette32(a5),pal
  260.  
  261.         suba.l    a0,a0            ;No newscreen stuct
  262.         lea    scrtags,a1
  263.     movea.l    intuibase(a5),a6
  264.     JSRLIB    OpenScreenTagList
  265.  
  266.     move.l    d0,wscr
  267.     move.l    d0,myscr(a5)
  268.     beq.b    e1
  269.  
  270.  
  271.     move.l    d0,a1
  272.     lea    sc_RastPort(a1),a1
  273.     move.l    rp_BitMap(a1),a0
  274.     lea    cgfxlocktags(pc),a1
  275.     move.l    cybbase(a5),a6
  276.     jsr    _LVOLockBitMapTagList(a6)    ;d0 = lock
  277.  
  278.     move.l    gfxboarddirectmem(pc),emuscr(a5)
  279.     
  280.     move.l    d0,a0                ;bitlock
  281.     jsr    _LVOUnLockBitMap(a6)
  282.  
  283.     movea.l    intuibase(a5),a6
  284.     move.w    xsize(a5),wwidth+2
  285.     move.w    ysize(a5),wheight+2
  286.     suba.l    a0,a0
  287.     lea    wintags,a1
  288.     JSRLIB    OpenWindowTagList
  289.     move.l    d0,mywin(a5)
  290.     beq.b    e1
  291.     movea.l    d0,a1
  292.  
  293.     move.l  wd_UserPort(a1),d0        ;IDCMP port
  294.     move.l    emuscr(a5),d2            ;chunky buffer
  295.     move.l    GfxBoardBitmapWidth(pc),d3    ;modulo (CV64 miatt ez az egyeduli korrekt mod)
  296.  
  297.     sub.w    xsize(a5),d3            ;modulo fix
  298.     
  299. e0:    move.l    #err_cyblib,d1
  300.     rts
  301.  
  302.  
  303. e1    move.l    #err_noscr,d1
  304.     rts
  305.  
  306. drv_CloseScreen:
  307.  
  308.     move.l    a0,a5
  309.     
  310.     tst.l    cybbase(a5)
  311.     beq.b    nemcyb
  312.     move.l    (4).w,a6
  313.     move.l    cybbase(a5),a1
  314.     jsr    _LVOCloseLibrary(a6)
  315.     clr.l    cybbase(a5)
  316.  
  317. nemcyb:    move.l    intuibase(a5),a6
  318.     move.l    mywin(a5),a0
  319.     tst.l    a0
  320.     beq.b    f1
  321.     JSRLIB    CloseWindow
  322.  
  323. f1    move.l    myscr(a5),a0
  324.     tst.l    a0
  325.     beq.b    f2
  326.     JSRLIB    CloseScreen
  327.  
  328. f2    movea.l    palette32(a5),a1
  329.         tst.l    a1
  330.     beq.b    f3
  331.     move.l    4.w,a6
  332.     JSRLIB    FreeVec        ;Deallocate translated palette
  333.  
  334. f3:    move.l    d0,emuscr(a5)    ;They were already freed
  335.     move.l    d0,palette32(a5)
  336.     move.l    d0,myscr(a5)
  337.     move.l    d0,mywin(a5)
  338.  
  339.     rts
  340.  
  341. drv_Refresh:
  342.  
  343.     move.l    emuscr(a0),d0
  344.         RTS
  345.  
  346. ;*** Constants
  347.  
  348.  
  349. cyblib:        dc.b    "cybergraphics.library",0
  350.  
  351.  
  352. scrtags:
  353.     dc.l    SA_Width
  354. width:    dc.l    0
  355.     dc.l    SA_Height
  356. height:    dc.l    0
  357.     dc.l    SA_Depth,8
  358.     dc.l    SA_Colors32
  359. pal:    dc.l    0
  360.     dc.l    SA_Title,scrtitle
  361.     dc.l    SA_ShowTitle,FALSE
  362.     dc.l    SA_DisplayID
  363.  
  364. ScrDisplayID:
  365.     dc.l    0
  366.  
  367.     dc.l    SA_Type,CUSTOMSCREEN
  368.     dc.l    SA_AutoScroll,TRUE
  369.     dc.l    SA_Overscan,OSCAN_STANDARD
  370.     dc.l    SA_Quiet,TRUE
  371.     dc.l    TAG_DONE
  372.  
  373. wintags:
  374.     dc.l    WA_Left,0
  375.     dc.l    WA_Top,0
  376.     dc.l    WA_Width
  377. wwidth:    dc.l    0
  378.     dc.l    WA_Height
  379. wheight:    dc.l    0
  380.     dc.l    WA_IDCMP,IDCMP_RAWKEY
  381.     dc.l    WA_Title,0
  382.     dc.l    WA_Backdrop,TRUE
  383.     dc.l    WA_RMBTrap,TRUE
  384.     dc.l    WA_Borderless,TRUE
  385.     dc.l    WA_NoCareRefresh,TRUE
  386.     dc.l    WA_CustomScreen
  387. wscr:    dc.l    0
  388.     dc.l    WA_SimpleRefresh,TRUE
  389.     dc.l    WA_Activate,TRUE
  390.     dc.l    TAG_DONE
  391.  
  392. scrtitle:    dc.b    'Flamingo Plus/4 emulator screen',0
  393.         EVEN
  394.  
  395. configfile:    dc.b    'cgfx.cfg',0
  396.         EVEN
  397.         
  398. cybmodetags:
  399.         dc.l    CYBRBIDTG_Depth,8
  400.         dc.l    CYBRBIDTG_NominalWidth
  401. cybwidth:    dc.l    0        
  402.         dc.l    CYBRBIDTG_NominalHeight
  403. cybheight:    dc.l    0
  404.         dc.l    TAG_END
  405.  
  406.  
  407. cgfxlocktags:    dc.l    LBMI_BASEADDRESS
  408.         dc.l    gfxboarddirectmem
  409.         dc.l    LBMI_BYTESPERROW
  410.         dc.l    GfxBoardBitmapWidth    
  411.  
  412.         dc.l    TAG_END
  413.  
  414. gfxboarddirectmem:
  415.         dc.l    0
  416. GfxBoardBitmapWidth:
  417.         dc.l    0
  418.  
  419. cybreqtags:    
  420.         dc.l    CYBRMREQ_MinWidth
  421. cgfxmodewidth:    dc.l    0        
  422.         dc.l    CYBRMREQ_MinHeight
  423. cgfxmodeheight:    dc.l    0
  424.         dc.l    CYBRMREQ_MinDepth
  425. cgfxmodedepth:    dc.l    8
  426.         dc.l    CYBRMREQ_MaxDepth
  427. cgfxmaxdepth:    dc.l    8
  428.         dc.l    CYBRMREQ_CModelArray
  429. cgfxpixform:    dc.l    cybreqcolors256
  430.         dc.l    TAG_END
  431.  
  432. cybreqcolors256:
  433.         dc.l    PIXFMT_LUT8
  434.         dc.l    TAG_END
  435.  
  436.  
  437. ;*** Errors
  438.  
  439. err_nomem:
  440.     dc.b    'Run out of memory',0
  441. err_noscr:
  442.     dc.b    'Cannot open screen',0
  443. err_cyblib:
  444.     dc.b    'Cannot open cybergraphics.library v40+',0
  445.  
  446.